package com.team.weigou.ui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.widget.ImageView;

import com.team.weigou.R;
import com.team.weigou.utils.AppUtils;

public class SplashActivity extends Activity {
    private ImageView img;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash_layout);

        initView();
    }

    private void initView() {
        img = (ImageView) findViewById(R.id.splash_img);
        //画面颜色渐变
        AnimationSet set = new AnimationSet(true);
        AlphaAnimation alphaAnimation = new AlphaAnimation(0.5f, 1.0f);
        alphaAnimation.setDuration(1500);
        set.addAnimation(alphaAnimation);

        //设置监听
        set.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                startIntent();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }
        });
        img.startAnimation(set);
    }

    private void startIntent() {
        Intent intent = null;
        if (AppUtils.isFirst(this)) {
            intent = new Intent(getApplicationContext(), GuideActivity.class);
        } else {
            intent = new Intent(getApplicationContext(), MainActivity.class);
        }
        startActivity(intent);
        this.finish();
    }

}
